import jsonp from 'common/js/jsonp.js'
import { commonParams } from './config'
import axios from 'axios'

// 获取排行榜数据
export function getHotKey() {
  const url = 'https://c.y.qq.com/splcloud/fcgi-bin/gethotkey.fcg'
  /* eslint-disable */
  let randCallbackName = '__jp' + String(Math.random()).slice(2,8)
  let params = Object.assign({}, commonParams, {
    callback: randCallbackName,
    jsonpCallback: randCallbackName,
    g_tk: 5381,
    uin: 0,
    format: 'json',
    notice: 0,
    platform: 'h5',
    needNewCode: 1
  })
  return jsonp(url, params, { name: randCallbackName })
}

// 获取排行榜数据
export function search(w, page, zhida, perpage=20) {
  const url = '/apimusic/getsuggests'
  /* eslint-disable */
  let randCallbackName = '__jp' + String(Math.random()).slice(2,8)
  let params = Object.assign({}, commonParams, {
    callback: randCallbackName,
    jsonpCallback: randCallbackName,
    g_tk: 5381,
    uin: 0,
    format: 'jsonp',
    notice: 0,
    platform: 'h5',
    needNewCode: 1,
    w: w,
    catZhida: zhida ? 1 : 0,
    zhidaqu: 1,
    t: 0,
    flag: 1,
    ie: 'utf-8',
    sem: 1,
    aggr: 0,
    perpage: perpage,
    n: perpage,
    p: page,
    remoteplace: 'txt.mqq.all'
  })

  return axios.get(url, {
    params: params
  }).then((res) => {
    return Promise.resolve(res.data)
  })

}

